package material.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * 布告板--天气预报布告板
 * 分析当天的平均气温，最高温度以及最低温度
 */
public class ForecastDisplayInner implements Observer, DisplayElement {
    Observable observable;
    private float currentPressure = 29.2f;//当前压力值
    private float lastPressure;//最终压力值

    public ForecastDisplayInner(Observable o) {
        this.observable = o;
        o.addObserver(this);
    }

    @Override
    public void display() {
        System.out.print("天气预报: ");
        if (currentPressure > lastPressure) {
            System.out.println("Improving weather on the way!");
        } else if (currentPressure == lastPressure) {
            System.out.println("More of the same");
        } else if (currentPressure < lastPressure) {
            System.out.println("Watch out for cooler, rainy weather");
        }
    }

    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof WeatherDataInner) {
            WeatherDataInner weatherDataInner = (WeatherDataInner) o;
            this.lastPressure = this.currentPressure;
            this.currentPressure = weatherDataInner.getPressure();
            this.display();
        }
    }
}
